package com.exwave.socialgame.myutils;

import com.exwave.socialgame.model_wolfgame.wolfdata.Room;

import java.util.HashMap;
import java.util.List;

public class WolfGameUtils {

    //抛出房间未开始游戏异常
    public static void isGaming(Room room) {
        if (room.getTimes() <= 0)
            throw new ParamsException("请先开始游戏");
        if (room.getData() <= 0)
            throw new ParamsException("当前禁止提交事件");
    }

    //判断int是否大于零
    public static void isIllegal(int n) {
        if (n < 0)
            throw new ParamsException("数据不合法(<0)");
    }

    //判断List为空
    public static void isListNull(List list, String msg) {
        if (list.size() <= 0) {
            throw new ParamsException(msg);
        }
    }

    //判断Object为空
    public static void isNullOrEmpty(Object object) {
        isNullOrEmpty(object, "对象为空，请检查数据合法性");
    }

    public static void isNullOrEmpty(Object object, String msg) {
        if (object == null || object == "") {
            throw new ParamsException(msg);
        }
    }

    //判断Object非空
    public static void isNotNullOrEmpty(Object object, String msg) {
        if (object != null && object != "")
            throw new ParamsException(msg);
    }

    //返回工具类
    public static HashMap<String, Object> returnFailure(String msg) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("code", 500);
        map.put("msg", msg);
        return map;
    }

    public static HashMap<String, Object> returnFailure(int code, String msg) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("code", code);
        map.put("msg", msg);
        return map;
    }

    public static HashMap<String, Object> returnSuccess() {
        return returnSuccess(null);
    }

    public static HashMap<String, Object> returnSuccess(int code, HashMap<String, Object> hashMap) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("code", code);
        map.put("msg", "success");
        if (hashMap != null)
            map.put("data", hashMap);
        return map;
    }

    public static HashMap<String, Object> returnSuccess(HashMap<String, Object> hashMap) {
        return returnSuccess(200, hashMap);
    }
}
